<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>首付款信息详情</title>
<jsp:include page="../../import.jsp" flush="true" />
<style type="text/css">
	a:link{text-decoration: none; color:blue; font-family: 微软雅黑;}
	a:visited{color:green;}
	a:hover{text-decoration: underline; color:#09f;}
	a:active{text-decoration: blink; color: yellow;}
</style>
</head>
<body class="iframeBody">
	<form id="fncPrjFstpyInfo_detail_form">
		<div class="fieldset1 tabel_col tabel_col_s clearFix ">
		
			<div class="caption">
				<span class="title">基本信息 </span>
			</div>
			
			<div class="fieldBox col_33">
				<div class="label">项目名称：</div>
				<div class="field">
					<span name="fncPrjNm" id="fncPrjNm"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">项目编号：</div>
				<div class="field">
					<span name="fncPrjIdStr" id="fncPrjIdStr"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">创建时间：</div>
				<div class="field">
					<span name="crtTm" id="crtTm"></span>
				</div>
			</div>
			
			<div class="fieldBox col_33">
				<div class="label">融资机构：</div>
				<div class="field">
					<span name="fundRasInsNm" id="fundRasInsNm"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">融资报价：</div>
				<div class="field">
					<span name="fncScmNm" id="fncScmNm"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">融资基数：</div>
				<div class="field">
					<span name="fncCrdnltNm" id="fncCrdnltNm"></span>
				</div>
			</div>
			
			<div class="fieldBox col_33">
				<div class="label">打折率：</div>
				<div class="field">
					<span name="dcnRate" id="dcnRate"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">计划融资起始日期：</div>
				<div class="field">
					<span name="stdt" id="stdt"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">计划融资终止日期：</div>
				<div class="field">
					<span name="eddt" id="eddt"></span>
				</div>
			</div>
			
			<div class="fieldBox col_33">
				<div class="label">授信合同号：</div>
				<div class="field">
					<span name="crCtrNo" id="crCtrNo"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">授信名称：</div>
				<div class="field">
					<span name="crNm" id="crNm"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">授信余额：</div>
				<div class="field">
					<span name="crBal" id="crBal"></span>
				</div>
			</div>
			
			
			<div class="fieldBox col_33">
				<div class="label">项目金额：</div>
				<div class="field">
					<span name="fncPrjAmt" id="fncPrjAmt"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">融资金额：</div>
				<div class="field">
					<span name="fncFiAmt" id="fncFiAmt"></span>
				</div>
			</div>
			<div class="fieldBox col_33">
				<div class="label">支付表数量：</div>
				<div class="field">
					<span name="payCnt" id="payCnt"></span>
				</div>
			</div>
			
			<div class="fieldBox col_33">
				<div class="label">产品名称：</div>
				<div class="field">
					<span name="pdNm" id="pdNm"></span>
				</div>
			</div>
			
			<div id="bankDiv">
				<div class="caption">
					<span class="title">付款信息 </span>
				</div>
			
				<div class="fieldBox col_33">
					<div class="label">实际融资金额：</div>
					<div class="field">
						<span name="acFiAmt" id="acFiAmt"></span>
						<span style="color:red">（是否坐扣：<span name="wthrFstPay" id="wthrFstPay"></span>）</span>
					</div>
				</div>
				<div class="fieldBox col_33">
					<div class="label">我司付款帐户：</div>
					<div class="field">
						<span name="fstpyPayAccno" id="fstpyPayAccno"></span>
					</div>
				</div>
				<div class="fieldBox col_33">
					<div class="label">机构收款帐户：</div>
					<div class="field">
						<span name="recvAccNum" id="recvAccNum"></span>
					</div>
				</div>
				
				<div class="fieldBox col_33">
					<div class="label">收款单位：</div>
					<div class="field">
						<span name="recvAccNm" id="recvAccNm"></span>
					</div>
				</div>
				
				<div class="fieldBox col_33">
					<div class="label">收款开户行号：</div>
					<div class="field">
						<span name="recvBanAccNum" id="recvBanAccNum"></span>
					</div>
				</div>
				<div class="fieldBox col_33">
					<div class="label">收款开户行名：</div>
					<div class="field">
						<span name="recvBanAccNm" id="recvBanAccNm"></span>
					</div>
				</div> 
				
			</div>
			
			<!-- hide data -->
			<div class="fieldBox col_100" style="display:none;">
				<div class="field">
					<input name="dataId" id="dataId" type="text" class="ui-textbox" value="${fncPrjId}">
				</div>
			</div>
			
		</div>
		
		<div class="fieldset1 tabel_col tabel_col_s clearFix " id="fstpyDiv">
			<div class="caption">
				<span class="title">付款明细 </span>
			</div>
			<div class="fieldBox"></div>
			<table id="fstpyTable" class="sq-formTable">
				<tbody>
					<tr>
						<td style="padding: 0;text-align: center;">
							<table id="tableMain" class="sq-formTable no-border">
								<thead>
									<tr>
										<th class="tbLabel" style="text-align: center;">费用名称</th>
										<th class="tbLabel" style="text-align: center;">费用金额</th>
										<th class="tbLabel" style="text-align: center;">已付金额</th>
										<th class="tbLabel" style="text-align: center;">付款时间</th>
									</tr>
								</thead>
								<tbody>
									<tr id="totalTr">
										<td style="text-align: right;">合计：</td>
										<td style="text-align: center;"><span name="totalCost" ></span></td>
										<td style="text-align: center;" ><span name="totalPay" ></span></td>
										<td style="text-align: center;" ></td>
									</tr>
								</tbody>
							</table>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
	</form>
	<script>
		$(function() {
		   $("#fncPrjFstpyInfo_detail_form").ligerForm({
                validate: true
           });
	       initData();
		});
		
		function initData(){
			var dataId = $("#dataId").val();
	    	if(!dataId)return;
	    	var _url = '<%=path%>/rfbase/fncprjfstpyinfo/getById.do';
	    	AjaxUtils.ajaxPost(_url, {fncPrjId:dataId}, callback);
    	}
		
		//新增回调
		function callback(msg){
			if(msg.success == 1){
				 setData(msg.data);//设置数据
			 }else{
				 UIUtils.alertError(msg.info);
			 }
		}
		
		//设置页面数据
	    function setData(data){
			
	    	$("#fncPrjIdStr").html(data.fncPrjIdStr);
	    	$("#fncPrjNm").html(data.fncPrjNm);
	    	$("#crtTm").html(renderDate(data.crtTm));
	    	$("#fundRasInsNm").html(data.fundRasInsNm);
	    	//$("#fncScmNm").html(data.fncScmNm);
	  		$("#fncScmNm").append("<a href=\"JavaScript:showSCMDetail('"+data.fncScmId+"')\">"+data.fncScmNm+"</a>");
	    	$("#fncCrdnltNm").html(data.fncCrdnltNm);
	    	$("#dcnRate").html(data.dcnRate*100+"%");
	    	$("#stdt").html(renderDate(data.stdt));
	    	$("#eddt").html(renderDate(data.eddt));
	    	//$("#crNm").html(data.crNm);
	    	$("#crNm").append("<a href=\"JavaScript:showBSCDetail('"+data.lgCId+"')\">"+data.crNm+"</a>");
	    	$("#pdNm").html(data.pdNm);
	    	//$("#crCtrNo").html(data.crCtrNo);
	    	$("#crCtrNo").append("<a href=\"JavaScript:showBSCDetail('"+data.lgCId+"')\">"+data.crCtrNo+"</a>");
	    	$("#crBal").html(commafy(data.crBal));
	    	$("#payCnt").html(data.payCnt);
	    	
	    	$("#fncPrjAmt").html(commafy(data.fncPrjAmt));
	    	$("#fncFiAmt").html(commafy(data.fncFiAmt));
	    	$("#wthrFstPay").html(renderYesNo(data.wthrDdctFstPay));
	    	$("#acFiAmt").html(commafy(data.acFiAmt));
	    	var payBank = data.bkAccInfoVO;
	    	if(null != payBank){
	    		$("#fstpyPayAccno").html(payBank.accNo);
	    	}
	    	var recvBank = data.baccInfoVO;
	    	if(null != recvBank){
	    		$("#recvAccNum").html(recvBank.accNum);
		    	$("#recvAccNm").html(recvBank.accNm);
		    	$("#recvBanAccNum").html(recvBank.banAccNum);
		    	$("#recvBanAccNm").html(recvBank.banAccNm);
	    	}
	    	
	    	var totalPayAmt = 0;
			var totalCostAmt = 0;
			//首付款信息
			var fstpyVos = data.fncPrjFstpyInfoVOs;
			for (var i = 0; i < fstpyVos.length; i++) {
				addRow();
				var tr = $('#tableMain tbody tr:eq('+i+')');
				tr.find("span[name='costNm']").html(fstpyVos[i].costNm);
				tr.find("span[name='costAmt']").html(commafy(fstpyVos[i].costAmt));
				tr.find("span[name='payAmt']").html(commafy(fstpyVos[i].payAmt));
				tr.find("span[name='fstpyTm']").html(renderDate(data.fstpyTm));
				totalCostAmt += fstpyVos[i].costAmt;
				totalPayAmt += fstpyVos[i].payAmt;
			}
			
			$('#totalTr').find("span[name='totalCost']").html(commafy(totalCostAmt));
			$('#totalTr').find("span[name='totalPay']").html(commafy(totalPayAmt));
			
			isWthrDdct(data.wthrFstPay);
	    	
		};
		
		 //格式化时间
		 function renderDate(value){
			var dateStr = "";
			if(null != value &&  ""!= value){
				var date = new Date(value);
				dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
			}
			return dateStr;
		 }
		 
		function addRow(fstpyVo){
			$('#totalTr').before('<tr>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="costNm" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="costAmt" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="payAmt" ></span>'+
					'</div>'+
				'</td>'+
				'<td style="text-align: center;">'+
					'<div class="field">'+
						'<span name="fstpyTm" ></span>'+
					'</div>'+
				'</td>'+
			'</tr>');
		}
		
		function isWthrDdct(val){
		//	if(val == 0){
			//	$('#bankDiv').show();
			//	$('#fstpyDiv').show();
			//}else{
			//	$('#bankDiv').hide();
			//	$('#fstpyDiv').hide();
			//}
		}
		
		//显示是否
		function renderYesNo(value){
			var dateStr = "";
			if(0 == value){
				dateStr = "否";
			}
			if(1 == value){
				dateStr = "是";
			}
			if(2 == value){
				dateStr = "是/否";
			}
			return dateStr;
		}
		
		//数字格式转换成千分位
		 function commafy(s){
		     return formatMoney(s);
		  }
		
		function formatMoney(number, places, symbol, thousand, decimal) {
			number = number || 0;
			places = !isNaN(places = Math.abs(places)) ? places : 2;
			// symbol = symbol !== undefined ? symbol : "$";
			symbol = symbol !== undefined ? symbol : "";
			thousand = thousand || ",";
			decimal = decimal || ".";
			var negative = number < 0 ? "-" : "", 
				i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10)+ "",
				j = (j = i.length) > 3 ? j % 3 : 0;
			return symbol
					+ negative
					+ (j ? i.substr(0, j) + thousand : "")
					+ i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand)
					+ (places ? decimal
					+ Math.abs(number - i).toFixed(places).slice(2) : "");
		}
		//授信详情
		function showBSCDetail(id){
			if(!id)return;
			var lgcId=id;
			Add_navTab('PrdSpl_3'+id,'授信详情','<%=path%>/rfbase/crbaseinfo/toDetailPage.do?lgcId='+lgcId);
		}
	 	 //查看融资报价
        function showSCMDetail(id){
    		var callback = function(){
    			 grid.reload();
    		}
    		var timestamp=new Date().getTime();
    		Add_navTab( 'tab_scm_bsc_info_detl'+timestamp,'查看融资报价','<%=path%>/rfbase/scmbaseinfo/toDetail.do?id='+id,callback);
      	}
	</script>
</body>
</html>